﻿using System;
using System.Security.Cryptography;
using System.Windows;

using Perseus.Plugins;

using Hetymine.Executioner.Commands;

namespace Hetymine.Executioner.Plugins.MD5 {
    public class MD5 : Plugin, IExecutable {
        public MD5() {
            this.PluginInfo = PluginInfo.FromAssembly(this.GetType().Assembly, "Blake Hancock");
            this.Name = "md5";
        }
        public string Name { get; protected set; }
        public bool Execute(string parameters) {
            byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(parameters);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

            byte[] hash = md5.ComputeHash(inputBytes);
            string hashString = string.Empty;

            for (int i = 0; i < hash.Length; i++) {
                hashString += Convert.ToString(hash[i], 16).PadLeft(2, '0');
            }

            Clipboard.SetText(hashString.PadLeft(32, '0'));

            return true;
        }
    }
}
